﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Final
{
    class Constant_Table
    {
        const int OFFSET = 100;

        List<int> integer;

        public Constant_Table()
        {
            integer = new List<int>();

            integer.Add(0);
            integer.Add(1);
        }

        /* Takes an integer to store in the constant table and checks to
         * see if it already exists or not and return the address of where
         * that literal is stored */
        public int Insert(int insert)
        {
            int location = 0;

            foreach (int x in integer)
            {
                if (x == insert)
                {
                    return location + OFFSET;
                }

                location++;
            }

            integer.Add(insert);

            return (integer.Count - 1) + OFFSET;
        }

        public void Print()
        {
            Console.WriteLine("\tConstant Table");

            int counter = 0;

            foreach (int i in integer)
            {
                Console.WriteLine(OFFSET + counter + ":\t" + i);
                counter++;
            }
        }
    }
}
